package a07_二叉树;

/**
 * <p>
 * a08_对称二叉树复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/4/7
 */
public class a08_对称二叉树复习3 {
    public static void main(String[] args) {
    }
    public boolean isSymmetric(TreeNode root) {
        return traversal(root.left, root.right);
    }

    private boolean traversal(TreeNode leftNode,TreeNode rightNode){
        if(leftNode == null && rightNode == null){
            return true;
        }else if(leftNode != null && rightNode == null){
            return false;
        }else if(leftNode == null && rightNode != null){
            return false;
        }else if(leftNode.val != rightNode.val){
            return false;
        }
        boolean outer = traversal(leftNode.left, rightNode.right);
        boolean inner = traversal(leftNode.right, rightNode.left);
        return outer && inner;
    }
}
